Temblortimer = 0
lvshake = 0
Arcoiriscolor1 = 255
Arcoiriscolor2 = 0
Arcoiriscolor3 = 0
ArcoirisFase = "Rojo"
Boxes = {}
Bubbles = {}
Dialogues = {}

function Box(text, fontinicial, personaje, cuerpo, diff, cajaY, boxmodel, boxcolor, index)
	while not Boxes[index] do
		table.insert(Boxes, {})
	end
	if Boxes[index].Activo then
		Boxes[index].Caja.Remove()
		Boxes[index].Caja = nil
		if Boxes[index].CaraActiva == true then
			Boxes[index].Cara.Remove()
			Boxes[index].Cara = nil
			Boxes[index].CaraActiva = false
		end
		if Boxes[index].CuerpoActivo == true then
			Boxes[index].Cuerpo.Remove()
			Boxes[index].Cuerpo = nil
			Boxes[index].CuerpoActivo = false
		end
		for i=1,#Boxes[index].Letras do
			if Boxes[index].Letras[i] ~= nil then
				Boxes[index].Letras[i].Remove()
				Boxes[index].Letras[i] = nil
			end
		end
		for i=1,#Boxes[index].Arcoiris do
			if Boxes[index].Arcoiris[i] ~= nil then
				Boxes[index].Arcoiris[i] = nil
			end
		end
		for i=1,#Boxes[index].Shake do
			if Boxes[index].Shake[i] ~= nil then
				Boxes[index].Shake[i] = nil
			end
		end
		for i=1,#Boxes[index].Temblar do
			if Boxes[index].Temblar[i] ~= nil then
				Boxes[index].Temblar[i] = nil
			end
		end
	end
	Boxes[index].Texto = ""
	Boxes[index].Activo = false
	if text ~= "" then
		if boxmodel ~= nil then
			Boxes[index].Caja = CreateSprite("Dialogs Library Sprites/Box/Box Models/"..boxmodel,"Top")
		else
			Boxes[index].Caja = CreateSprite("Dialogs Library Sprites/Box/Box Models/Caja","Top")
		end
		Boxes[index].Caja.SetVar("CambiarColoresArcoiris", true)
		Boxes[index].Caja.MoveTo( 320, cajaY )
		if boxcolor ~= nil and type(boxcolor) == "table" then
			Boxes[index].Caja.color = {boxcolor[1], boxcolor[2], boxcolor[3]}
		elseif boxcolor ~= nil and boxcolor == "rainbow" then
			Boxes[index].Caja.SetVar("PermitirArcoiris", true)
		elseif boxcolor ~= nil and boxcolor ~= "" then
			Boxes[index].Caja.color = {Hex(string.sub(boxcolor,1,2))/255,Hex(string.sub(boxcolor,3,4))/255,Hex(string.sub(boxcolor,5,6))/255}
		end
		Boxes[index].Arcoiris = {}
		Boxes[index].Temblar = {}
		Boxes[index].Letras = {}
		Boxes[index].Shake = {}
		table.insert(Boxes[index].Arcoiris, Boxes[index].Caja)
		Boxes[index].Primero = nil
		Boxes[index].Retroceder = nil
		Boxes[index].Espacio = nil
		Boxes[index].AgregarLetrasArcoiris = false
		Boxes[index].AgregarLetrasTembladoras = false
		Boxes[index].Texto = text
		Boxes[index].LetraXsig = 81
		Boxes[index].LetraY = cajaY + 53
		Boxes[index].Voz = "ui"
		Boxes[index].Skip = true
		Boxes[index].Temblor = false
		Boxes[index].VelHabla = 1
		Boxes[index].TiempoW = 1
		Boxes[index].TiempoWSet = false
		Boxes[index].ClaseCara1 = personaje
		Boxes[index].Color1 = 255
		Boxes[index].Color2 = 255
		Boxes[index].Color3 = 255
		Boxes[index].starColor1 = ""
		Boxes[index].starColor2 = ""
		Boxes[index].starColor3 = ""
		if fontinicial == nil or fontinicial == "" then
			Boxes[index].TipoLetraCaja = "uidialog"
		else
			Boxes[index].TipoLetraCaja = fontinicial
		end
		Boxes[index].Asterisco = CreateSprite("Dialogs Library Sprites/Box/Fonts/" .. Boxes[index].TipoLetraCaja .. "/ast","Top")
		Boxes[index].TipoCara = personaje
		if personaje == "" then
			Boxes[index].Asterisco.MoveTo(( Boxes[index].LetraXsig - 20 ), ( Boxes[index].LetraY - 17 ))
			Boxes[index].CaraActiva = false
		else
			Boxes[index].Cara = CreateProjectileAbs("Dialogs Library Sprites/Box/Mugshots/" .. personaje, 95, cajaY, "Top")
			Boxes[index].Cara.SetVar("posy", Boxes[index].Cara.absy)
			Boxes[index].LetraXsig = 210
			Boxes[index].Asterisco.MoveTo(( Boxes[index].LetraXsig - 20 ), ( Boxes[index].LetraY - 17 ))
			Boxes[index].CaraActiva = true
			table.insert(Boxes[index].Temblar, Boxes[index].Cara)
			if cuerpo ~= "" then
				Boxes[index].CuerpoActivo = true
				Boxes[index].Cuerpo = CreateProjectileAbs("Dialogs Library Sprites/Box/Mugshots/" .. cuerpo, 95, cajaY, "Top")
				Boxes[index].difcara = Boxes[index].Cara.sprite.height/2 - diff
				Boxes[index].difcuerpo = Boxes[index].Cuerpo.sprite.height/2 - diff
				if Boxes[index].difcara > Boxes[index].difcuerpo then
					while Boxes[index].difcara > Boxes[index].difcuerpo do
						Boxes[index].difcara = difcara - 0.5
						Boxes[index].difcuerpo = difcuerpo + 0.5
					end
				elseif Boxes[index].difcuerpo > Boxes[index].difcara then
					while Boxes[index].difcuerpo > Boxes[index].difcara do
						Boxes[index].difcara = Boxes[index].difcara + 0.5
						Boxes[index].difcuerpo = Boxes[index].difcuerpo - 0.5
					end
				end
				Boxes[index].Cara.Move(0, Boxes[index].difcara)
				Boxes[index].Cuerpo.Move(0, -Boxes[index].difcuerpo)
				Boxes[index].Cara.SetVar("posy", cajaY + Boxes[index].difcara)
				Boxes[index].Cuerpo.SetVar("posy", cajaY - Boxes[index].difcuerpo)
				table.insert(Boxes[index].Temblar, Boxes[index].Cuerpo)
			end
		end
		table.insert(Boxes[index].Letras, Boxes[index].Asterisco)
		Boxes[index].LetraX = Boxes[index].LetraXsig
		Boxes[index].Activo = true
		LetrasUpdate(index)
	end
end

function Dialog(text, posicion, fontinicial, asterisquino, index)
	while not Dialogues[index] do
		table.insert(Dialogues, {})
	end
	if Dialogues[index].Activo then
		for i=1,#Dialogues[index].DLetras do
			if Dialogues[index].DLetras[i] ~= nil then
				Dialogues[index].DLetras[i].Remove()
				Dialogues[index].DLetras[i] = nil
			end
		end
		for i=1,#Dialogues[index].Arcoiris do
			if Dialogues[index].Arcoiris[i] ~= nil then
				Dialogues[index].Arcoiris[i] = nil
			end
		end
		for i=1,#Dialogues[index].Shake do
			if Dialogues[index].Shake[i] ~= nil then
				Dialogues[index].Shake[i] = nil
			end
		end
	end
	Dialogues[index].DTexto = ""
	Dialogues[index].Activo = false
	if text ~= "" then
		if asterisquino == nil or asterisquino == "" then
			Dialogues[index].Dasterisquino = false
		else
			Dialogues[index].Dasterisquino = asterisquino
		end
		Dialogues[index].DAgregarLetrasArcoiris = false
		Dialogues[index].DAgregarLetrasTembladoras = false
		Dialogues[index].DTexto = text
		Dialogues[index].DLetraXsig = (posicion.X or 121)
		Dialogues[index].DLetraY = posicion.Y
		Dialogues[index].DVoz = "ui"
		Dialogues[index].Primero = nil
		Dialogues[index].Retroceder = nil
		Dialogues[index].Espacio = nil
		Dialogues[index].DSkip = true
		Dialogues[index].DTemblor = false
		Dialogues[index].DVisibilidad = nil
		Dialogues[index].DVelHabla = 1
		Dialogues[index].DTiempoW = 1
		Dialogues[index].DTiempoWSet = false
		Dialogues[index].DColor1 = 255
		Dialogues[index].DColor2 = 255
		Dialogues[index].DColor3 = 255
		Dialogues[index].DstarColor1 = ""
		Dialogues[index].DstarColor2 = ""
		Dialogues[index].DstarColor3 = ""
		if fontinicial == nil or fontinicial == "" then
			Dialogues[index].DTipoLetraCaja = "uidialog"
		else
			Dialogues[index].DTipoLetraCaja = fontinicial
		end
		Dialogues[index].DAsterisco = CreateSprite("Dialogs Library Sprites/Box/Fonts/" .. Dialogues[index].DTipoLetraCaja .. "/ast","Top")
		Dialogues[index].DAsterisco.MoveTo(( Dialogues[index].DLetraXsig - 20 ), ( Dialogues[index].DLetraY - 17 ))
		Dialogues[index].DAsterisco.SetVar("CambiarColoresArcoiris", true)
		if Dialogues[index].Dasterisquino == false then
			Dialogues[index].DAsterisco.alpha = 0
		end
		Dialogues[index].DLetras = {}
		Dialogues[index].Arcoiris = {}
		Dialogues[index].Shake = {}
		table.insert(Dialogues[index].DLetras, Dialogues[index].DAsterisco)
		table.insert(Dialogues[index].Arcoiris, Dialogues[index].DAsterisco)
		Dialogues[index].DLetraX = Dialogues[index].DLetraXsig
		Dialogues[index].Activo = true
		DialogLetrasUpdate(index)
	end
end

function Bubble(text, TipoBurbuja, burX, burY, BLetraX, BLetraY, index)
	while not Bubbles[index] do
		table.insert(Bubbles, {})
	end
	if Bubbles[index].Activo then
		Bubbles[index].SprBurbuja.Remove()
		Bubbles[index].SprBurbuja = nil
		for i=1,#Bubbles[index].Burbuja do
			if Bubbles[index].Burbuja[i] ~= nil then
				Bubbles[index].Burbuja[i].Remove()
				Bubbles[index].Burbuja[i] = nil
			end
		end
		for i=1,#Bubbles[index].Arcoiris do
			if Bubbles[index].Arcoiris[i] ~= nil then
				Bubbles[index].Arcoiris[i] = nil
			end
		end
		for i=1,#Bubbles[index].Shake do
			if Bubbles[index].Shake[i] ~= nil then
				Bubbles[index].Shake[i] = nil
			end
		end
	end
	Bubbles[index].Comentario = ""
	Bubbles[index].Activo = false
	if text ~= "" then
		Bubbles[index].SprBurbuja = CreateSprite("UI/SpeechBubbles/" .. TipoBurbuja,"Top")
		Bubbles[index].SprBurbuja.SetVar("CambiarColoresArcoiris", true)
		Bubbles[index].SprBurbuja.MoveTo(burX, burY)
		Bubbles[index].Arcoiris = {}
		Bubbles[index].Burbuja = {}
		Bubbles[index].Shake = {}
		table.insert(Bubbles[index].Arcoiris, Bubbles[index].SprBurbuja)
		Bubbles[index].Comentario = text
		Bubbles[index].Primero = nil
		Bubbles[index].Retroceder = nil
		Bubbles[index].Espacio = nil
		Bubbles[index].BAgregarLetrasArcoiris = false
		Bubbles[index].BAgregarLetrasTembladoras = false
		Bubbles[index].BurbujaXsig = burX - Bubbles[index].SprBurbuja.width/2 + BLetraX
		Bubbles[index].BurbujaY = burY - Bubbles[index].SprBurbuja.height/2 + BLetraY
		Bubbles[index].BurbujaVoz = "character"
		Bubbles[index].BurbujaSkip = true
		Bubbles[index].BurbujaVelHabla = 1
		Bubbles[index].BurbujaW = 1
		Bubbles[index].BurbujaWSet = false
		Bubbles[index].BurbujaLetra = "monster/"
		Bubbles[index].BColor1 = 0
		Bubbles[index].BColor2 = 0
		Bubbles[index].BColor3 = 0
		Bubbles[index].BurbujaX = Bubbles[index].BurbujaXsig
		Bubbles[index].Activo = true
	end
end

function LetrasUpdate(index)
	while (string.sub(Boxes[index].Texto,1,1) == "\r" or string.sub(Boxes[index].Texto,1,1) == "\n" or string.sub(Boxes[index].Texto,1,1) == "[") and (Boxes[index].TiempoW <= 0 or Boxes[index].Skip == "Skipeando") do
		if string.sub(Boxes[index].Texto,1,1) == "\r" or string.sub(Boxes[index].Texto,1,1) == "\n" then
			if Boxes[index].Tiny then
				Boxes[index].LetraY = Boxes[index].LetraY - 18
			else
				Boxes[index].LetraY = Boxes[index].LetraY - 36
			end
			Boxes[index].LetraXsig = Boxes[index].LetraX
			if string.sub(Boxes[index].Texto,1,1) == "\n" then
				Boxes[index].Asterisco = CreateSprite("Dialogs Library Sprites/Box/Fonts/" .. Boxes[index].TipoLetraCaja .. "/ast","Top")
				if Boxes[index].Tiny then
					Boxes[index].Asterisco.Scale(0.5, 0.5)
					Boxes[index].Asterisco.MoveTo(( Boxes[index].LetraXsig - 10 ), ( Boxes[index].LetraY - 9 ))
				else
					Boxes[index].Asterisco.MoveTo(( Boxes[index].LetraXsig - 20 ), ( Boxes[index].LetraY - 17 ))
				end
				table.insert(Boxes[index].Letras, Boxes[index].Asterisco)
			end
			Boxes[index].Primero = nil
			Boxes[index].Retroceder = nil
			Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
		elseif string.sub(Boxes[index].Texto,1,1) == "[" then
			Boxes[index].TextoCmm = ""
			Boxes[index].TextoNum = ""
			Boxes[index].TextoDato = ""
			Boxes[index].Texto2puntos = false
			Boxes[index].TextoComa = false
			Boxes[index].TextoColor = false
			Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
			while string.sub(Boxes[index].Texto,1,1) ~= "]" do
				if string.sub(Boxes[index].Texto,1,1) == ":" then
					Boxes[index].Texto2puntos = true
					Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
				elseif string.sub(Boxes[index].Texto,1,1) == "," and Boxes[index].TextoColor == false then
					Boxes[index].TextoComa = true
					Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
				elseif TextoComa == true then
					Boxes[index].TextoDato = Boxes[index].TextoDato .. string.sub(Boxes[index].Texto,1,1)
					Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
				elseif Boxes[index].Texto2puntos == true then
					if string.sub(Boxes[index].Texto,1,1) == "{" then
						Boxes[index].TextoColor = true
					end
					Boxes[index].TextoNum = Boxes[index].TextoNum .. string.sub(Boxes[index].Texto,1,1)
					Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
				else
					Boxes[index].TextoCmm = Boxes[index].TextoCmm .. string.sub(Boxes[index].Texto,1,1)
					Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
				end
			end
			Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
			if(Boxes[index].TextoCmm == "noskip") then
				Boxes[index].Skip = false
			elseif(Boxes[index].TextoCmm == "w") then
				Boxes[index].TiempoW = tonumber(Boxes[index].TextoNum)
				Boxes[index].TiempoWSet = true
			elseif(Boxes[index].TextoCmm == "waittall") then
				Boxes[index].VelHabla = tonumber(Boxes[index].TextoNum)
			elseif(Boxes[index].TextoCmm == "novoice") then
				Boxes[index].Voz = ""
			elseif(Boxes[index].TextoCmm == "voice") then
				Boxes[index].Voz = Boxes[index].TextoNum
			elseif(Boxes[index].TextoCmm == "instant") then
				Boxes[index].Skip = "Instantaneo"
			elseif(Boxes[index].TextoCmm == "font") then
				Boxes[index].TipoLetraCaja = Boxes[index].TextoNum
			elseif(Boxes[index].TextoCmm == "color") then
				if string.sub(Boxes[index].TextoNum,1,1) == "{" then
					if Boxes[index].AgregarLetrasArcoiris == true then
						Boxes[index].AgregarLetrasArcoiris = false
					end
					local colores1 = ""
					local colores2 = ""
					local colores3 = ""
					local coloresfase = 1
					Boxes[index].TextoNum = string.sub(Boxes[index].TextoNum,2)
					while string.sub(Boxes[index].TextoNum,1,1) ~= "}" do
						if string.sub(Boxes[index].TextoNum,1,1) == "," then
							coloresfase = coloresfase + 1
						else
							if coloresfase == 1 then
								colores1 = colores1 .. string.sub(Boxes[index].TextoNum,1,1)
							elseif coloresfase == 2 then
								colores2 = colores2 .. string.sub(Boxes[index].TextoNum,1,1)
							elseif coloresfase == 3 then
								colores3 = colores3 .. string.sub(Boxes[index].TextoNum,1,1)
							end
						end
						Boxes[index].TextoNum = string.sub(Boxes[index].TextoNum,2)
					end
					Boxes[index].Color1 = tonumber(colores1)
					Boxes[index].Color2 = tonumber(colores2)
					Boxes[index].Color3 = tonumber(colores3)
				elseif Boxes[index].TextoNum == "rainbow" then
					if Boxes[index].AgregarLetrasArcoiris == false then
						Boxes[index].AgregarLetrasArcoiris = true
					elseif Boxes[index].AgregarLetrasArcoiris == true then
						Boxes[index].AgregarLetrasArcoiris = false
					end
				else
					Boxes[index].Color1 = Hex(string.sub(TextoNum,1,2))
					Boxes[index].Color2 = Hex(string.sub(TextoNum,3,4))
					Boxes[index].Color3 = Hex(string.sub(TextoNum,5,6))
				end
			elseif(Boxes[index].TextoCmm == "starcolor") then
				if string.sub(Boxes[index].TextoNum,1,1) == "{" then
					local starcolorfase = 1
					Boxes[index].TextoNum = string.sub(Boxes[index].TextoNum,2)
					while string.sub(Boxes[index].TextoNum,1,1) ~= "}" do
						if string.sub(Boxes[index].TextoNum,1,1) == "," then
							starcolorfase = starcolorfase + 1
						else
							if starcolorfase == 1 then
								Boxes[index].starColor1 = Boxes[index].starColor1 .. string.sub(Boxes[index].TextoNum,1,1)
							elseif starcolorfase == 2 then
								Boxes[index].starColor2 = Boxes[index].starColor2 .. string.sub(Boxes[index].TextoNum,1,1)
							elseif starcolorfase == 3 then
								Boxes[index].starColor3 = Boxes[index].starColor3 .. string.sub(Boxes[index].TextoNum,1,1)
							end
						end
						Boxes[index].TextoNum = string.sub(Boxes[index].TextoNum,2)
					end
					Boxes[index].Asterisco.color = {tonumber(Boxes[index].starColor1)/255,tonumber(Boxes[index].starColor2)/255,tonumber(Boxes[index].starColor3)/255}
					Boxes[index].starColor1 = ""
					Boxes[index].starColor2 = ""
					Boxes[index].starColor3 = ""
				elseif Boxes[index].TextoNum == "rainbow" then
					Boxes[index].Asterisco.SetVar("PermitirArcoiris", true)
					table.insert(Boxes[index].Arcoiris, Boxes[index].Asterisco)
				else
					Boxes[index].Asterisco.color = {Hex(string.sub(Boxes[index].TextoNum,1,2))/255,Hex(string.sub(Boxes[index].TextoNum,3,4))/255,Hex(string.sub(Boxes[index].TextoNum,5,6))/255}
				end
			elseif(Boxes[index].TextoCmm == "stareffect") then
				if Boxes[index].TextoNum == "shake" then
					if Boxes[index].TextoDato == "" then
						Boxes[index].TextoDato = "2"
					end
					Boxes[index].Asterisco.SetVar("intensidad", tonumber(Boxes[index].TextoDato))
					Boxes[index].Asterisco.SetVar("X", Boxes[index].Asterisco.x)
					Boxes[index].Asterisco.SetVar("Y", Boxes[index].Asterisco.y)
					table.insert(Boxes[index].Shake, Boxes[index].Asterisco)
				end
			elseif(Boxes[index].TextoCmm == "SetAnimation") then
				Boxes[index].Cara.sprite.SetAnimation({"Dialogs Library Sprites/Box/Mugshots/" .. Boxes[index].TipoCara,"Dialogs Library Sprites/Box/Mugshots/" .. Boxes[index].TextoNum}, 0.15)
				Boxes[index].CaraAnimada = Boxes[index].TextoNum
			elseif(Boxes[index].TextoCmm == "StopAnimation") then
				Boxes[index].Cara.sprite.StopAnimation()
				Boxes[index].CaraAnimada = ""
			elseif(Boxes[index].TextoCmm == "SetCara") then
				Boxes[index].Cara.sprite.Set("Dialogs Library Sprites/Box/Mugshots/" .. Boxes[index].TextoNum)
				Boxes[index].TipoCara = Boxes[index].TextoNum
			elseif(Boxes[index].TextoCmm == "shake") then
				Boxes[index].Temblor = true
				lvshake = tonumber(Boxes[index].TextoNum)
			elseif(Boxes[index].TextoCmm == "stopshake") then
				Boxes[index].Temblor = false
				lvshake = 0
			elseif(Boxes[index].TextoCmm == "MoveTo") then
				Boxes[index].LetraXsig = tonumber(Boxes[index].TextoNum)
			elseif(Boxes[index].TextoCmm == "effect") then
				if Boxes[index].TextoNum == "shake" then
					if Boxes[index].TextoDato ~= "" then
						Boxes[index].shakeintensity = tonumber(Boxes[index].TextoDato)
					else
						Boxes[index].shakeintensity = 2
					end
					Boxes[index].AgregarLetrasTembladoras = true
				elseif Boxes[index].TextoNum == "none" then
					Boxes[index].AgregarLetrasTembladoras = false
				end
			elseif(Boxes[index].TextoCmm == "SetSpace") then
				Boxes[index].Espacio = Boxes[index].TextoNum
			elseif(Boxes[index].TextoCmm == "func") then
				if Boxes[index].TextoDato ~= "" then
					Encounter.Call(Boxes[index].TextoNum,Boxes[index].TextoDato)
				else
					Encounter.Call(Boxes[index].TextoNum)
				end
			elseif (Boxes[index].TextoCmm == "tinyletters") then
				Boxes[index].Tiny = true
				Boxes[index].LetraY = Boxes[index].LetraY - 9
			elseif (Boxes[index].TextoCmm == "startiny") then
				Boxes[index].Asterisco.Scale(0.5, 0.5)
				Boxes[index].Asterisco.MoveTo(Boxes[index].Asterisco.x - 10, Boxes[index].Asterisco.y)
				Boxes[index].LetraX = Boxes[index].LetraX - 15
				Boxes[index].LetraXsig = Boxes[index].LetraXsig - 15
			elseif(Boxes[index].TextoCmm == "next") then
				Boxes[index].Texto = ""
				Box("","","","","","","","",index)
			end
		end
	end
	if Boxes[index].TiempoW <= 0 or Boxes[index].Skip == "Skipeando" then
		if string.sub(Boxes[index].Texto,1,1) ~= "" and string.sub(Boxes[index].Texto,1,1) ~= " " then
			Boxes[index].TipoLetra = "Minuscula/"
			Boxes[index].LetraUnitaria = string.sub(Boxes[index].Texto,1,1)
			if Boxes[index].LetraUnitaria == string.upper(Boxes[index].LetraUnitaria) then
				Boxes[index].TipoLetra = "Mayuscula/"
			end
			Boxes[index].TipoLetra = Boxes[index].TipoLetra .. string.sub(Boxes[index].Texto,1,1)
			if string.sub(Boxes[index].Texto,1,1) == "." then
				Boxes[index].TipoLetra = "Signos/dot"
			elseif string.sub(Boxes[index].Texto,1,1) == "," then
				Boxes[index].TipoLetra = "Signos/przc"
			elseif string.sub(Boxes[index].Texto,1,1) == "'" then
				Boxes[index].TipoLetra = "Signos/aps"
			elseif string.sub(Boxes[index].Texto,1,1) == "!" then
				Boxes[index].TipoLetra = "Signos/!"
			elseif string.sub(Boxes[index].Texto,1,1) == "?" then
				Boxes[index].TipoLetra = "Signos/qst"
			elseif string.sub(Boxes[index].Texto,1,1) == "-" then
				Boxes[index].TipoLetra = "Signos/guion"
			elseif string.sub(Boxes[index].Texto,1,1) == "_" then
				Boxes[index].TipoLetra = "Signos/glargo"
				Boxes[index].Retroceder = (Boxes[index].Espacio or 2)
				if not Boxes[index].Primero then
					Boxes[index].Primero = 0
				end
			elseif string.sub(Boxes[index].Texto,1,1) == ":" then
				Boxes[index].TipoLetra = "Signos/dotdot"
			elseif string.sub(Boxes[index].Texto,1,1) == ";" then
				Boxes[index].TipoLetra = "Signos/dotprzc"
			elseif string.sub(Boxes[index].Texto,1,1) == "=" then
				Boxes[index].TipoLetra = "Signos/="
			elseif string.sub(Boxes[index].Texto,1,1) == "(" then
				Boxes[index].TipoLetra = "Signos/parL"
			elseif string.sub(Boxes[index].Texto,1,1) == ")" then
				Boxes[index].TipoLetra = "Signos/parR"
			elseif string.sub(Boxes[index].Texto,1,1) == "0" then
				Boxes[index].TipoLetra = "Numeros/0"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "1" then
				Boxes[index].TipoLetra = "Numeros/1"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "2" then
				Boxes[index].TipoLetra = "Numeros/2"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "3" then
				Boxes[index].TipoLetra = "Numeros/3"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "4" then
				Boxes[index].TipoLetra = "Numeros/4"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "5" then
				Boxes[index].TipoLetra = "Numeros/5"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "6" then
				Boxes[index].TipoLetra = "Numeros/6"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "7" then
				Boxes[index].TipoLetra = "Numeros/7"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "8" then
				Boxes[index].TipoLetra = "Numeros/8"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Boxes[index].Texto,1,1) == "9" then
				Boxes[index].TipoLetra = "Numeros/9"
				if Boxes[index].TipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			end
			if Boxes[index].Primero and Boxes[index].Primero == 0 then
				Boxes[index].Primero = 1
				Boxes[index].Retroceder = nil
			elseif Boxes[index].Primero and Boxes[index].Primero == 1 and Boxes[index].TipoLetra ~= "Signos/glargo" then
				Boxes[index].Primero = nil
				Boxes[index].Retroceder = nil
			end
			Boxes[index].Letra = CreateSprite("Dialogs Library Sprites/Box/Fonts/" .. Boxes[index].TipoLetraCaja .. "/" .. Boxes[index].TipoLetra,"Top")
			Boxes[index].Letra.color = {Boxes[index].Color1/255,Boxes[index].Color2/255,Boxes[index].Color3/255}
			if Boxes[index].Tiny then
				Boxes[index].Letra.Scale(0.5, 0.5)
				Boxes[index].Letra.MoveTo(Boxes[index].LetraXsig - (Boxes[index].Retroceder or 0) + Boxes[index].Letra.width/4,Boxes[index].LetraY - Boxes[index].Letra.height/4)
				Boxes[index].LetraXsig = Boxes[index].LetraXsig + Boxes[index].Letra.width/2 + (Boxes[index].Espacio or 2) - (Boxes[index].Retroceder or 0)
			else
				Boxes[index].Letra.MoveTo(Boxes[index].LetraXsig - (Boxes[index].Retroceder or 0) + Boxes[index].Letra.width/2,Boxes[index].LetraY - Boxes[index].Letra.height/2)
				Boxes[index].LetraXsig = Boxes[index].LetraXsig + Boxes[index].Letra.width + (Boxes[index].Espacio or 2) - (Boxes[index].Retroceder or 0)
			end
			Boxes[index].Retroceder = nil
			table.insert(Boxes[index].Letras, Boxes[index].Letra)
			if Boxes[index].AgregarLetrasArcoiris == true then
				Boxes[index].Letra.SetVar("PermitirArcoiris", true)
				table.insert(Boxes[index].Arcoiris, Boxes[index].Letra)
			end
			if Boxes[index].AgregarLetrasTembladoras == true then
				Boxes[index].Letra.SetVar("intensidad", Boxes[index].shakeintensity)
				Boxes[index].Letra.SetVar("X", Boxes[index].LetraXsig - Boxes[index].Letra.width/2*Boxes[index].Letra.xscale)
				Boxes[index].Letra.SetVar("Y", Boxes[index].LetraY - Boxes[index].Letra.height/2*Boxes[index].Letra.yscale)
				table.insert(Boxes[index].Shake, Boxes[index].Letra)
			end
			if Boxes[index].Voz ~= "" and Boxes[index].Skip ~= "Skipeando" and Boxes[index].Skip ~= "Instantaneo" then
				Audio.PlaySound("Voices/" .. Boxes[index].Voz)
			end
		else
			if Boxes[index].Tiny then
				Boxes[index].LetraXsig = Boxes[index].LetraXsig + 11
			else
				Boxes[index].LetraXsig = Boxes[index].LetraXsig + 22
			end
		end
		Boxes[index].Texto = string.sub(Boxes[index].Texto,2)
	end
end

function DialogLetrasUpdate(index)
	while (string.sub(Dialogues[index].DTexto,1,1) == "\r" or string.sub(Dialogues[index].DTexto,1,1) == "\n" or string.sub(Dialogues[index].DTexto,1,1) == "[") and (Dialogues[index].DTiempoW <= 0 or Dialogues[index].DSkip == "Skipeando") do
		if string.sub(Dialogues[index].DTexto,1,1) == "\r" or string.sub(Dialogues[index].DTexto,1,1) == "\n" then
			if Dialogues[index].Tiny then
				Dialogues[index].DLetraY = Dialogues[index].DLetraY - 18
			else
				Dialogues[index].DLetraY = Dialogues[index].DLetraY - 36
			end
			Dialogues[index].DLetraXsig = Dialogues[index].DLetraX
			if string.sub(Dialogues[index].DTexto,1,1) == "\n" then
				Dialogues[index].DAsterisco = CreateSprite("Dialogs Library Sprites/Box/Fonts/" .. Dialogues[index].DTipoLetraCaja .. "/ast","Top")
				if Dialogues[index].Tiny then
					Dialogues[index].DAsterisco.Scale(0.5, 0.5)
					Dialogues[index].DAsterisco.MoveTo(( Dialogues[index].DLetraXsig - 10 ), ( Dialogues[index].DLetraY - 9 ))
				else
					Dialogues[index].DAsterisco.MoveTo(( Dialogues[index].DLetraXsig - 20 ), ( Dialogues[index].DLetraY - 17 ))
				end
				if Dialogues[index].Dasterisquino == false then
					Dialogues[index].DAsterisco.alpha = 0
				end
				table.insert(Dialogues[index].DLetras, Dialogues[index].DAsterisco)
			end
			Dialogues[index].Primero = nil
			Dialogues[index].Retroceder = nil
			Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
		elseif string.sub(Dialogues[index].DTexto,1,1) == "[" then
			Dialogues[index].DTextoCmm = ""
			Dialogues[index].DTextoNum = ""
			Dialogues[index].DTextoDato = ""
			Dialogues[index].DTexto2puntos = false
			Dialogues[index].DTextoComa = false
			Dialogues[index].DTextoColor = false
			Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
			while string.sub(Dialogues[index].DTexto,1,1) ~= "]" do
				if string.sub(Dialogues[index].DTexto,1,1) == ":" then
					Dialogues[index].DTexto2puntos = true
					Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
				elseif string.sub(Dialogues[index].DTexto,1,1) == "," and Dialogues[index].DTextoColor == false then
					Dialogues[index].DTextoComa = true
					Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
				elseif Dialogues[index].DTextoComa == true then
					Dialogues[index].DTextoDato = Dialogues[index].DTextoDato .. string.sub(Dialogues[index].DTexto,1,1)
					Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
				elseif Dialogues[index].DTexto2puntos == true then
					if string.sub(Dialogues[index].DTexto,1,1) == "{" then
						Dialogues[index].DTextoColor = true
					end
					Dialogues[index].DTextoNum = Dialogues[index].DTextoNum .. string.sub(Dialogues[index].DTexto,1,1)
					Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
				else
					Dialogues[index].DTextoCmm = Dialogues[index].DTextoCmm .. string.sub(Dialogues[index].DTexto,1,1)
					Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
				end
			end
			Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
			if(Dialogues[index].DTextoCmm == "noskip") then
				Dialogues[index].DSkip = false
			elseif(Dialogues[index].DTextoCmm == "w") then
				Dialogues[index].DTiempoW = tonumber(Dialogues[index].DTextoNum)
				Dialogues[index].DTiempoWSet = true
			elseif(Dialogues[index].DTextoCmm == "waittall") then
				Dialogues[index].DVelHabla = tonumber(Dialogues[index].DTextoNum)
			elseif(Dialogues[index].DTextoCmm == "novoice") then
				Dialogues[index].DVoz = ""
			elseif(Dialogues[index].DTextoCmm == "voice") then
				Dialogues[index].DVoz = Dialogues[index].DTextoNum
			elseif(Dialogues[index].DTextoCmm == "instant") then
				Dialogues[index].DSkip = "Instantaneo"
			elseif(Dialogues[index].DTextoCmm == "font") then
				Dialogues[index].DTipoLetraCaja = Dialogues[index].DTextoNum
			elseif(Dialogues[index].DTextoCmm == "color") then
				if string.sub(Dialogues[index].DTextoNum,1,1) == "{" then
					if Dialogues[index].DAgregarLetrasArcoiris == true then
						Dialogues[index].DAgregarLetrasArcoiris = false
					end
					local colores1 = ""
					local colores2 = ""
					local colores3 = ""
					local coloresfase = 1
					Dialogues[index].DTextoNum = string.sub(Dialogues[index].DTextoNum,2)
					while string.sub(Dialogues[index].DTextoNum,1,1) ~= "}" do
						if string.sub(Dialogues[index].DTextoNum,1,1) == "," then
							coloresfase = coloresfase + 1
						else
							if coloresfase == 1 then
								colores1 = colores1 .. string.sub(Dialogues[index].DTextoNum,1,1)
							elseif coloresfase == 2 then
								colores2 = colores2 .. string.sub(Dialogues[index].DTextoNum,1,1)
							elseif coloresfase == 3 then
								colores3 = colores3 .. string.sub(Dialogues[index].DTextoNum,1,1)
							end
						end
						Dialogues[index].DTextoNum = string.sub(Dialogues[index].DTextoNum,2)
					end
					Dialogues[index].DColor1 = tonumber(colores1)
					Dialogues[index].DColor2 = tonumber(colores2)
					Dialogues[index].DColor3 = tonumber(colores3)
				elseif Dialogues[index].DTextoNum == "rainbow" then
					if Dialogues[index].DAgregarLetrasArcoiris == false then
						Dialogues[index].DAgregarLetrasArcoiris = true
					elseif Dialogues[index].DAgregarLetrasArcoiris == true then
						Dialogues[index].DAgregarLetrasArcoiris = false
					end
				else
					Dialogues[index].DColor1 = Hex(string.sub(Dialogues[index].DTextoNum,1,2))
					Dialogues[index].DColor2 = Hex(string.sub(Dialogues[index].DTextoNum,3,4))
					Dialogues[index].DColor3 = Hex(string.sub(Dialogues[index].DTextoNum,5,6))
				end
			elseif(Dialogues[index].DTextoCmm == "starcolor") then
				if string.sub(Dialogues[index].DTextoNum,1,1) == "{" then
					local starcolorfase = 1
					Dialogues[index].DTextoNum = string.sub(Dialogues[index].DTextoNum,2)
					while string.sub(Dialogues[index].DTextoNum,1,1) ~= "}" do
						if string.sub(Dialogues[index].DTextoNum,1,1) == "," then
							starcolorfase = starcolorfase + 1
						else
							if starcolorfase == 1 then
								Dialogues[index].DstarColor1 = Dialogues[index].DstarColor1 .. string.sub(Dialogues[index].DTextoNum,1,1)
							elseif starcolorfase == 2 then
								Dialogues[index].DstarColor2 = Dialogues[index].DstarColor2 .. string.sub(Dialogues[index].DTextoNum,1,1)
							elseif starcolorfase == 3 then
								Dialogues[index].DstarColor3 = Dialogues[index].DstarColor3 .. string.sub(Dialogues[index].DTextoNum,1,1)
							end
						end
						Dialogues[index].DTextoNum = string.sub(Dialogues[index].DTextoNum,2)
					end
					Dialogues[index].DAsterisco.color = {tonumber(Dialogues[index].DstarColor1)/255,tonumber(Dialogues[index].DstarColor2)/255,tonumber(Dialogues[index].DstarColor3)/255}
				elseif Dialogues[index].DTextoNum == "rainbow" then
					Dialogues[index].DAsterisco.SetVar("PermitirArcoiris", true)
				else
					Dialogues[index].DAsterisco.color = {Hex(string.sub(Dialogues[index].DTextoNum,1,2))/255,Hex(string.sub(Dialogues[index].DTextoNum,3,4))/255,Hex(string.sub(Dialogues[index].DTextoNum,5,6))/255}
				end
			elseif(Dialogues[index].DTextoCmm == "stareffect") then
				if Dialogues[index].DTextoNum == "shake" then
					if Dialogues[index].DTextoDato == "" then
						Dialogues[index].DTextoDato = "2"
					end
					Dialogues[index].DAsterisco.SetVar("intensidad", tonumber(Dialogues[index].DTextoDato))
					Dialogues[index].DAsterisco.SetVar("X", Dialogues[index].DAsterisco.x)
					Dialogues[index].DAsterisco.SetVar("Y", Dialogues[index].DAsterisco.y)
					table.insert(Shake, DAsterisco)
				end
			elseif(Dialogues[index].DTextoCmm == "MoveTo") then
				Dialogues[index].DLetraXsig = tonumber(Dialogues[index].DTextoNum)
			elseif(Dialogues[index].DTextoCmm == "MoveToY") then
				Dialogues[index].DLetraY = tonumber(Dialogues[index].DTextoNum)
			elseif(Dialogues[index].DTextoCmm == "MoveY") then
				Dialogues[index].DLetraY = Dialogues[index].DLetraY + tonumber(Dialogues[index].DTextoNum)
			elseif(Dialogues[index].DTextoCmm == "MoveX") then
				Dialogues[index].DLetraXsig = Dialogues[index].DLetraXsig + tonumber(Dialogues[index].DTextoNum)
			elseif(Dialogues[index].DTextoCmm == "effect") then
				if Dialogues[index].DTextoNum == "shake" then
					if Dialogues[index].DTextoDato ~= "" then
						Dialogues[index].shakeintensity = tonumber(Dialogues[index].DTextoDato)
					else
						Dialogues[index].shakeintensity = 2
					end
					Dialogues[index].DAgregarLetrasTembladoras = true
				elseif Dialogues[index].DTextoNum == "none" then
					Dialogues[index].DAgregarLetrasTembladoras = false
				end
			elseif(Dialogues[index].DTextoCmm == "SetSpace") then
				Dialogues[index].Espacio = Dialogues[index].DTextoNum
			elseif(Dialogues[index].DTextoCmm == "func") then
				if Dialogues[index].DTextoDato ~= "" then
					Encounter.Call(Dialogues[index].DTextoNum,Dialogues[index].DTextoDato)
				else
					Encounter.Call(Dialogues[index].DTextoNum)
				end
			elseif (Dialogues[index].DTextoCmm == "tinyletters") then
				Dialogues[index].Tiny = true
				Dialogues[index].DLetraY = Dialogues[index].DLetraY - 9
			elseif (Dialogues[index].DTextoCmm == "startiny") then
				Dialogues[index].DAsterisco.Scale(0.5, 0.5)
				Dialogues[index].DAsterisco.MoveTo(Dialogues[index].DAsterisco.x - 10, Dialogues[index].DAsterisco.y)
				Dialogues[index].DLetraX = Dialogues[index].DLetraX - 15
				Dialogues[index].DLetraXsig = Dialogues[index].DLetraXsig - 15
			elseif(Dialogues[index].DTextoCmm == "next") then
				Dialogues[index].DTexto = ""
				Dialog("","","","",index)
			end
		end
	end
	if Dialogues[index].DTiempoW <= 0 or Dialogues[index].DSkip == "Skipeando" then
		if string.sub(Dialogues[index].DTexto,1,1) ~= "" and string.sub(Dialogues[index].DTexto,1,1) ~= " " then
			Dialogues[index].DTipoLetra = "Minuscula/"
			Dialogues[index].DLetraUnitaria = string.sub(Dialogues[index].DTexto,1,1)
			if Dialogues[index].DLetraUnitaria == string.upper(Dialogues[index].DLetraUnitaria) then
				Dialogues[index].DTipoLetra = "Mayuscula/"
			end
			Dialogues[index].DTipoLetra = Dialogues[index].DTipoLetra .. string.sub(Dialogues[index].DTexto,1,1)
			if string.sub(Dialogues[index].DTexto,1,1) == "." then
				Dialogues[index].DTipoLetra = "Signos/dot"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "," then
				Dialogues[index].DTipoLetra = "Signos/przc"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "'" then
				Dialogues[index].DTipoLetra = "Signos/aps"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "!" then
				Dialogues[index].DTipoLetra = "Signos/!"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "?" then
				Dialogues[index].DTipoLetra = "Signos/qst"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "-" then
				Dialogues[index].DTipoLetra = "Signos/guion"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "_" then
				Dialogues[index].DTipoLetra = "Signos/glargo"
				Dialogues[index].Retroceder = (Dialogues[index].Espacio or 2)
				if not Dialogues[index].Primero then
					Dialogues[index].Primero = 0
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == ":" then
				Dialogues[index].DTipoLetra = "Signos/dotdot"
			elseif string.sub(Dialogues[index].DTexto,1,1) == ";" then
				Dialogues[index].DTipoLetra = "Signos/dotprzc"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "*" then
				Dialogues[index].DTipoLetra = "Signos/ast"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "=" then
				Dialogues[index].DTipoLetra = "Signos/="
			elseif string.sub(Dialogues[index].DTexto,1,1) == "(" then
				Dialogues[index].DTipoLetra = "Signos/parL"
			elseif string.sub(Dialogues[index].DTexto,1,1) == ")" then
				Dialogues[index].DTipoLetra = "Signos/parR"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "/" then
				Dialogues[index].DTipoLetra = "Signos/slash"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "#" then
				Dialogues[index].DTipoLetra = "Signos/hashtag"
			elseif string.sub(Dialogues[index].DTexto,1,1) == "0" then
				Dialogues[index].DTipoLetra = "Numeros/0"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "1" then
				Dialogues[index].DTipoLetra = "Numeros/1"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "2" then
				Dialogues[index].DTipoLetra = "Numeros/2"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "3" then
				Dialogues[index].DTipoLetra = "Numeros/3"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "4" then
				Dialogues[index].DTipoLetra = "Numeros/4"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "5" then
				Dialogues[index].DTipoLetra = "Numeros/5"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "6" then
				Dialogues[index].DTipoLetra = "Numeros/6"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "7" then
				Dialogues[index].DTipoLetra = "Numeros/7"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "8" then
				Dialogues[index].DTipoLetra = "Numeros/8"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Dialogues[index].DTexto,1,1) == "9" then
				Dialogues[index].DTipoLetra = "Numeros/9"
				if Dialogues[index].DTipoLetraCaja == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			end
			if Dialogues[index].Primero and Dialogues[index].Primero == 0 then
				Dialogues[index].Primero = 1
				Dialogues[index].Retroceder = nil
			elseif Dialogues[index].Primero and Dialogues[index].Primero == 1 and Dialogues[index].DTipoLetra ~= "Signos/glargo" then
				Dialogues[index].Primero = nil
				Dialogues[index].Retroceder = nil
			end
			Dialogues[index].DLetra = CreateSprite("Dialogs Library Sprites/Box/Fonts/" .. Dialogues[index].DTipoLetraCaja .. "/" .. Dialogues[index].DTipoLetra,"Top")
			Dialogues[index].DLetra.color = {Dialogues[index].DColor1/255,Dialogues[index].DColor2/255,Dialogues[index].DColor3/255}
			if Dialogues[index].Tiny then
				Dialogues[index].DLetra.Scale(0.5, 0.5)
				Dialogues[index].DLetra.MoveTo(Dialogues[index].DLetraXsig - (Dialogues[index].Retroceder or 0) + Dialogues[index].DLetra.width/4,Dialogues[index].DLetraY - Dialogues[index].DLetra.height/4)
				Dialogues[index].DLetraXsig = Dialogues[index].DLetraXsig + Dialogues[index].DLetra.width/2 + (Dialogues[index].Espacio or 2) - (Dialogues[index].Retroceder or 0)
			else
				Dialogues[index].DLetra.MoveTo(Dialogues[index].DLetraXsig - (Dialogues[index].Retroceder or 0) + Dialogues[index].DLetra.width/2,Dialogues[index].DLetraY - Dialogues[index].DLetra.height/2)
				Dialogues[index].DLetraXsig = Dialogues[index].DLetraXsig + Dialogues[index].DLetra.width + (Dialogues[index].Espacio or 2) - (Dialogues[index].Retroceder or 0)
			end
			Dialogues[index].Retroceder = nil
			table.insert(Dialogues[index].DLetras, Dialogues[index].DLetra)
			if Dialogues[index].DAgregarLetrasArcoiris == true then
				Dialogues[index].DLetra.SetVar("PermitirArcoiris", true)
				table.insert(Dialogues[index].Arcoiris, Dialogues[index].DLetra)
			end
			if Dialogues[index].DAgregarLetrasTembladoras == true then
				Dialogues[index].DLetra.SetVar("intensidad", Dialogues[index].shakeintensity)
				Dialogues[index].DLetra.SetVar("X", Dialogues[index].DLetraXsig - Dialogues[index].DLetra.width/2*Dialogues[index].DLetra.xscale)
				Dialogues[index].DLetra.SetVar("Y", Dialogues[index].DLetraY - Dialogues[index].DLetra.height/2*Dialogues[index].DLetra.yscale)
				table.insert(Dialogues[index].Shake, Dialogues[index].DLetra)
			end
			if Dialogues[index].DVoz ~= "" and Dialogues[index].DSkip ~= "Skipeando" and Dialogues[index].DSkip ~= "Instantaneo" then
				Audio.PlaySound("Voices/" .. Dialogues[index].DVoz)
			end
		else
			if Dialogues[index].Tiny then
				Dialogues[index].DLetraXsig = Dialogues[index].DLetraXsig + 11
			else
				Dialogues[index].DLetraXsig = Dialogues[index].DLetraXsig + 22
			end
		end
		Dialogues[index].DTexto = string.sub(Dialogues[index].DTexto,2)
	end
end

function BurbujaUpdate(index)
	while (string.sub(Bubbles[index].Comentario,1,1) == "\n" or string.sub(Bubbles[index].Comentario,1,1) == "[") and (Bubbles[index].BurbujaW <= 0 or Bubbles[index].BurbujaSkip == "Skipeando") do
		if string.sub(Bubbles[index].Comentario,1,1) == "\n" then
			Bubbles[index].BurbujaY = Bubbles[index].BurbujaY - 20
			Bubbles[index].BurbujaXsig = Bubbles[index].BurbujaX
			Bubbles[index].Primero = nil
			Bubbles[index].Retroceder = nil
			Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
		elseif string.sub(Bubbles[index].Comentario,1,1) == "[" then
			Bubbles[index].BTextoCmm = ""
			Bubbles[index].BTextoNum = ""
			Bubbles[index].BTextoDato = ""
			Bubbles[index].BTexto2puntos = false
			Bubbles[index].BTextoComa = false
			Bubbles[index].BTextoColor = false
			Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
			while string.sub(Bubbles[index].Comentario,1,1) ~= "]" do
				if string.sub(Bubbles[index].Comentario,1,1) == ":" then
					Bubbles[index].BTexto2puntos = true
					Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
				elseif string.sub(Bubbles[index].Comentario,1,1) == "," and Bubbles[index].BTextoColor == false then
					Bubbles[index].BTextoComa = true
					Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
				elseif Bubbles[index].BTextoComa == true then
					Bubbles[index].BTextoDato = Bubbles[index].BTextoDato .. string.sub(Bubbles[index].Comentario,1,1)
					Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
				elseif Bubbles[index].BTexto2puntos == true then
					if string.sub(Bubbles[index].Comentario,1,1) == "{" then
						Bubbles[index].BTextoColor = true
					end
					Bubbles[index].BTextoNum = Bubbles[index].BTextoNum .. string.sub(Bubbles[index].Comentario,1,1)
					Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
				else
					Bubbles[index].BTextoCmm = Bubbles[index].BTextoCmm .. string.sub(Bubbles[index].Comentario,1,1)
					Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
				end
			end
			Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
			if(Bubbles[index].BTextoCmm == "noskip") then
				Bubbles[index].BurbujaSkip = false
			elseif(Bubbles[index].BTextoCmm == "font") then
				Bubbles[index].BurbujaLetra = Bubbles[index].BTextoNum .. "/"
			elseif(Bubbles[index].BTextoCmm == "w") then
				Bubbles[index].BurbujaW = tonumber(Bubbles[index].BTextoNum)
				Bubbles[index].BurbujaWSet = true
			elseif(Bubbles[index].BTextoCmm == "waittall") then
				Bubbles[index].BurbujaVelHabla = tonumber(Bubbles[index].BTextoNum)
			elseif(Bubbles[index].BTextoCmm == "novoice") then
				Bubbles[index].BurbujaVoz = ""
			elseif(Bubbles[index].BTextoCmm == "voice") then
				Bubbles[index].BurbujaVoz = Bubbles[index].BTextoNum
			elseif(Bubbles[index].BTextoCmm == "instant") then
				Bubbles[index].BurbujaSkip = "Instantaneo"
			elseif(Bubbles[index].BTextoCmm == "color") then
				if string.sub(Bubbles[index].BTextoNum,1,1) == "{" then
					if Bubbles[index].BAgregarLetrasArcoiris == true then
						Bubbles[index].BAgregarLetrasArcoiris = false
					end
					local colores1 = ""
					local colores2 = ""
					local colores3 = ""
					local coloresfase = 1
					Bubbles[index].BTextoNum = string.sub(Bubbles[index].BTextoNum,2)
					while string.sub(Bubbles[index].BTextoNum,1,1) ~= "}" do
						if string.sub(Bubbles[index].BTextoNum,1,1) == "," then
							coloresfase = coloresfase + 1
						else
							if coloresfase == 1 then
								colores1 = colores1 .. string.sub(Bubbles[index].BTextoNum,1,1)
							elseif coloresfase == 2 then
								colores2 = colores2 .. string.sub(Bubbles[index].BTextoNum,1,1)
							elseif coloresfase == 3 then
								colores3 = colores3 .. string.sub(Bubbles[index].BTextoNum,1,1)
							end
						end
						Bubbles[index].BTextoNum = string.sub(Bubbles[index].BTextoNum,2)
					end
					Bubbles[index].BColor1 = tonumber(colores1)
					Bubbles[index].BColor2 = tonumber(colores2)
					Bubbles[index].BColor3 = tonumber(colores3)
				elseif Bubbles[index].BTextoNum == "rainbow" then
					if Bubbles[index].BAgregarLetrasArcoiris == false then
						Bubbles[index].BAgregarLetrasArcoiris = true
					elseif Bubbles[index].BAgregarLetrasArcoiris == true then
						Bubbles[index].BAgregarLetrasArcoiris = false
					end
				else
					Bubbles[index].BColor1 = Hex(string.sub(Bubbles[index].BTextoNum,1,2))
					Bubbles[index].BColor2 = Hex(string.sub(Bubbles[index].BTextoNum,3,4))
					Bubbles[index].BColor3 = Hex(string.sub(Bubbles[index].BTextoNum,5,6))
				end
			elseif(Bubbles[index].BTextoCmm == "MoveTo") then
				Bubbles[index].BurbujaXsig = tonumber(Bubbles[index].BTextoNum)
			elseif(Bubbles[index].BTextoCmm == "MoveX") then
				Bubbles[index].BurbujaXsig = Bubbles[index].BurbujaXsig + tonumber(Bubbles[index].BTextoNum)
			elseif(Bubbles[index].BTextoCmm == "effect") then
				if Bubbles[index].BTextoNum == "shake" then
					if Bubbles[index].BTextoDato ~= "" then
						Bubbles[index].shakeintensity = tonumber(Bubbles[index].BTextoDato)
					else
						Bubbles[index].shakeintensity = 2
					end
					Bubbles[index].BAgregarLetrasTembladoras = true
				elseif Bubbles[index].BTextoNum == "none" then
					Bubbles[index].BAgregarLetrasTembladoras = false
				end
			elseif(Bubbles[index].BTextoCmm == "SetSpace") then
				Bubbles[index].Espacio = Bubbles[index].BTextoNum
			elseif(Bubbles[index].BTextoCmm == "func") then
				if Bubbles[index].BTextoDato ~= "" then
					Encounter.Call(Bubbles[index].BTextoNum,Bubbles[index].BTextoDato)
				else
					Encounter.Call(Bubbles[index].BTextoNum)
				end
			elseif(Bubbles[index].BTextoCmm == "next") then
				Bubbles[index].Comentario = ""
				Bubble("","","","","","",index)
			end
		end
	end
	if Bubbles[index].BurbujaW <= 0 or Bubbles[index].BurbujaSkip == "Skipeando" then
		if string.sub(Bubbles[index].Comentario,1,1) ~= "" and string.sub(Bubbles[index].Comentario,1,1) ~= " " then
			Bubbles[index].LetraBurbujaTipo = "Minuscula/"
			Bubbles[index].LetraBUnitaria = string.sub(Bubbles[index].Comentario,1,1)
			if Bubbles[index].LetraBUnitaria == string.upper(Bubbles[index].LetraBUnitaria) then
				Bubbles[index].LetraBurbujaTipo = "Mayuscula/"
			end
			Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. Bubbles[index].LetraBurbujaTipo .. string.sub(Bubbles[index].Comentario,1,1)
			if string.sub(Bubbles[index].Comentario,1,1) == "." then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/dot"
			elseif string.sub(Bubbles[index].Comentario,1,1) == "," then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/przc"
			elseif string.sub(Bubbles[index].Comentario,1,1) == "'" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/aps"
			elseif string.sub(Bubbles[index].Comentario,1,1) == "!" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/!"
			elseif string.sub(Bubbles[index].Comentario,1,1) == "?" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/qst"
			elseif string.sub(Bubbles[index].Comentario,1,1) == "-" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/guion"
			elseif string.sub(Bubbles[index].Comentario,1,1) == "_" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/glargo"
				Bubbles[index].Retroceder = (Bubbles[index].Espacio or 2)
				if not Bubbles[index].Primero then
					Bubbles[index].Primero = 0
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == ":" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/dotdot"
			elseif string.sub(Bubbles[index].Comentario,1,1) == ";" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Signos/dotprzc"
			elseif string.sub(Bubbles[index].Comentario,1,1) == "0" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/0"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "1" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/1"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "2" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/2"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "3" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/3"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "4" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/4"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "5" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/5"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "6" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/6"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "7" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/7"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "8" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/8"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			elseif string.sub(Bubbles[index].Comentario,1,1) == "9" then
				Bubbles[index].LetraBurbujaTipo = Bubbles[index].BurbujaLetra .. "Numeros/9"
				if Bubbles[index].BurbujaLetra == "papyrus" then
					error("\n\nThe font \"papyrus\" can't use Numbers.")
				end
			end
			if Bubbles[index].Primero and Bubbles[index].Primero == 0 then
				Bubbles[index].Primero = 1
				Bubbles[index].Retroceder = nil
			elseif Bubbles[index].Primero and Bubbles[index].Primero == 1 and Bubbles[index].LetraBurbujaTipo ~= (Bubbles[index].BurbujaLetra .. "Signos/glargo") then
				Bubbles[index].Primero = nil
				Bubbles[index].Retroceder = nil
			end
			Bubbles[index].BLetraSpr = CreateSprite("Dialogs Library Sprites/Bubble/" .. Bubbles[index].LetraBurbujaTipo,"Top")
			Bubbles[index].BLetraSpr.MoveTo(Bubbles[index].BurbujaXsig - (Bubbles[index].Retroceder or 0) + Bubbles[index].BLetraSpr.width/2,Bubbles[index].BurbujaY - Bubbles[index].BLetraSpr.height/2)
			Bubbles[index].BLetraSpr.color = {Bubbles[index].BColor1/255,Bubbles[index].BColor2/255,Bubbles[index].BColor3/255}
			Bubbles[index].BurbujaXsig = Bubbles[index].BurbujaXsig + Bubbles[index].BLetraSpr.width + (Bubbles[index].Espacio or 2) - (Bubbles[index].Retroceder or 0)
			Bubbles[index].Retroceder = nil
			table.insert(Bubbles[index].Burbuja, Bubbles[index].BLetraSpr)
			if Bubbles[index].BAgregarLetrasArcoiris == true then
				Bubbles[index].BLetraSpr.SetVar("PermitirArcoiris", true)
				table.insert(Bubbles[index].Arcoiris, Bubbles[index].BLetraSpr)
			end
			if Bubbles[index].BAgregarLetrasTembladoras == true then
				Bubbles[index].BLetraSpr.SetVar("intensidad", Bubbles[index].shakeintensity)
				Bubbles[index].BLetraSpr.SetVar("X", Bubbles[index].BurbujaXsig - Bubbles[index].BLetraSpr.width/2)
				Bubbles[index].BLetraSpr.SetVar("Y", Bubbles[index].BurbujaY - Bubbles[index].BLetraSpr.height/2)
				table.insert(Bubbles[index].Shake, Bubbles[index].BLetraSpr)
			end
			if Bubbles[index].BurbujaVoz ~= "" and Bubbles[index].BurbujaSkip ~= "Skipeando" and Bubbles[index].BurbujaSkip ~= "Instantaneo" then
				Audio.PlaySound("Voices/" .. Bubbles[index].BurbujaVoz)
			end
		else
			Bubbles[index].BurbujaXsig = Bubbles[index].BurbujaXsig + 11
		end
		Bubbles[index].Comentario = string.sub(Bubbles[index].Comentario,2)
	end
end

function Hex(codigo)
	local multiplicador = 0
	local sumatoria = 0
	local valor = 0
	if string.sub(codigo,1,1) == "0" then
		multiplicador = 0
	elseif string.sub(codigo,1,1) == "1" then
		multiplicador = 1
	elseif string.sub(codigo,1,1) == "2" then
		multiplicador = 2
	elseif string.sub(codigo,1,1) == "3" then
		multiplicador = 3
	elseif string.sub(codigo,1,1) == "4" then
		multiplicador = 4
	elseif string.sub(codigo,1,1) == "5" then
		multiplicador = 5
	elseif string.sub(codigo,1,1) == "6" then
		multiplicador = 6
	elseif string.sub(codigo,1,1) == "7" then
		multiplicador = 7
	elseif string.sub(codigo,1,1) == "8" then
		multiplicador = 8
	elseif string.sub(codigo,1,1) == "9" then
		multiplicador = 9
	elseif string.sub(codigo,1,1) == "a" then
		multiplicador = 10
	elseif string.sub(codigo,1,1) == "b" then
		multiplicador = 11
	elseif string.sub(codigo,1,1) == "c" then
		multiplicador = 12
	elseif string.sub(codigo,1,1) == "d" then
		multiplicador = 13
	elseif string.sub(codigo,1,1) == "e" then
		multiplicador = 14
	elseif string.sub(codigo,1,1) == "f" then
		multiplicador = 15
	end
	if string.sub(codigo,2,2) == "0" then
		sumatoria = 0
	elseif string.sub(codigo,2,2) == "2" then
		sumatoria = 1
	elseif string.sub(codigo,2,2) == "2" then
		sumatoria = 2
	elseif string.sub(codigo,2,2) == "3" then
		sumatoria = 3
	elseif string.sub(codigo,2,2) == "4" then
		sumatoria = 4
	elseif string.sub(codigo,2,2) == "5" then
		sumatoria = 5
	elseif string.sub(codigo,2,2) == "6" then
		sumatoria = 6
	elseif string.sub(codigo,2,2) == "7" then
		sumatoria = 7
	elseif string.sub(codigo,2,2) == "8" then
		sumatoria = 8
	elseif string.sub(codigo,2,2) == "9" then
		sumatoria = 9
	elseif string.sub(codigo,2,2) == "a" then
		sumatoria = 10
	elseif string.sub(codigo,2,2) == "b" then
		sumatoria = 11
	elseif string.sub(codigo,2,2) == "c" then
		sumatoria = 12
	elseif string.sub(codigo,2,2) == "d" then
		sumatoria = 13
	elseif string.sub(codigo,2,2) == "e" then
		sumatoria = 14
	elseif string.sub(codigo,2,2) == "f" then
		sumatoria = 15
	end
	valor = (16*multiplicador)+sumatoria
	return valor
end

function DialogUpdate()
	Temblortimer = Temblortimer + 1
	CambiarColoresArcoiris = nil
	for i=1,#Boxes do
		if Boxes[i].Texto ~= "" then
			if ( Input.Cancel == 1 and Boxes[i].Skip == true ) or Boxes[i].Skip == "Instantaneo" then
				Boxes[i].Skip = "Skipeando"
				Boxes[i].TiempoW = 0
				while Boxes[i].Skip == "Skipeando" and Boxes[i].Texto ~= "" do
					LetrasUpdate(i)
				end
				Boxes[i].TiempoW = Boxes[i].VelHabla
			else
				if Boxes[i].TiempoW <= 0 then
					LetrasUpdate(i)
					if Boxes[i].TiempoWSet == false then
						Boxes[i].TiempoW = Boxes[i].VelHabla
					else
						Boxes[i].TiempoWSet = false
					end
				else
					Boxes[i].TiempoW = Boxes[i].TiempoW - 0.5
				end
			end
			if Boxes[i].Caja then
				Boxes[i].Caja.layer = "Top"
			end
			for j=1,#Boxes[i].Letras do
				if Boxes[i].Letras[j].isactive then
					Boxes[i].Letras[j].layer = "Top"
				end
			end
		else
			if Input.Confirm == 1 and Boxes[i].Activo == true then
				Box("", "", "", "", "", "", "", "", i)
			end
		end
		for j=1,#Boxes[i].Temblar do
			local misil = Boxes[i].Temblar[j]
			local posY = misil.GetVar("posy")
			if Boxes[i].Temblor == true then
				local vel = math.random(lvshake,-lvshake)
				local tipo = math.random(4)
				if Temblortimer%4 == 0 then
					if tipo == 1 then
						x = 95 + vel
						y = posY + vel
					elseif tipo == 2 then
						x = 95 - vel
						y = posY + vel
					elseif tipo == 3 then
						x = 95 + vel
						y = posY - vel
					else
						x = 95 - vel
						y = posY - vel
					end
					misil.MoveToAbs(x, y)
				end
			else
				local posY = misil.GetVar("posy")
				misil.MoveToAbs(95, posY)
			end
		end
		for j=1,#Boxes[i].Arcoiris do
			local epilepsia = Boxes[i].Arcoiris[j]
			if epilepsia.GetVar("CambiarColoresArcoiris") and not CambiarColoresArcoiris then
				ChangeColors()
			end
			if epilepsia.GetVar("PermitirArcoiris") then
				epilepsia.color = {Arcoiriscolor1/255, Arcoiriscolor2/255, Arcoiriscolor3/255}
			end
		end
		for j=1,#Boxes[i].Shake do
			local temblor = Boxes[i].Shake[j]
			local vel = math.random(temblor.GetVar("intensidad"),-temblor.GetVar("intensidad"))
			local tipo = math.random(4)
			if Temblortimer%2 == 0 then
				if tipo == 1 then
					x = temblor.GetVar("X") + vel
					y = temblor.GetVar("Y") + vel
				elseif tipo == 2 then
					x = temblor.GetVar("X") - vel
					y = temblor.GetVar("Y") + vel
				elseif tipo == 3 then
					x = temblor.GetVar("X") + vel
					y = temblor.GetVar("Y") - vel
				else
					x = temblor.GetVar("X") - vel
					y = temblor.GetVar("Y") - vel
				end
				temblor.MoveToAbs(x, y)
			end
		end
	end
	for i=1,#Dialogues do
		if Dialogues[i].DTexto ~= "" then
			if ( Input.Cancel == 1 and Dialogues[i].DSkip == true ) or Dialogues[i].DSkip == "Instantaneo" then
				Dialogues[i].DSkip = "Skipeando"
				Dialogues[i].DTiempoW = 0
				while Dialogues[i].DSkip == "Skipeando" and Dialogues[i].DTexto ~= "" do
					DialogLetrasUpdate(i)
				end
				Dialogues[i].DTiempoW = Dialogues[i].DVelHabla
			else
				if Dialogues[i].DTiempoW <= 0 then
					DialogLetrasUpdate(i)
					if Dialogues[i].DTiempoWSet == false then
						Dialogues[i].DTiempoW = Dialogues[i].DVelHabla
					else
						Dialogues[i].DTiempoWSet = false
					end
				else
					Dialogues[i].DTiempoW = Dialogues[i].DTiempoW - 0.5
				end
			end
			for j=1,#Dialogues[i].DLetras do
				if Dialogues[i].DLetras[j].isactive then
					Dialogues[i].DLetras[j].layer = "Top"
				end
			end
		else
			if Input.Confirm == 1 and Dialogues[i].Activo == true then
				Dialog("", "", "", "", i)
			end
		end
		for j=1,#Dialogues[i].Arcoiris do
			local epilepsia = Dialogues[i].Arcoiris[j]
			if epilepsia.GetVar("CambiarColoresArcoiris") and not CambiarColoresArcoiris then
				ChangeColors()
			end
			if epilepsia.GetVar("PermitirArcoiris") then
				epilepsia.color = {Arcoiriscolor1/255, Arcoiriscolor2/255, Arcoiriscolor3/255}
			end
		end
		for j=1,#Dialogues[i].Shake do
			local temblor = Dialogues[i].Shake[j]
			local vel = math.random(temblor.GetVar("intensidad"),-temblor.GetVar("intensidad"))
			local tipo = math.random(4)
			if Temblortimer%2 == 0 then
				if tipo == 1 then
					x = temblor.GetVar("X") + vel
					y = temblor.GetVar("Y") + vel
				elseif tipo == 2 then
					x = temblor.GetVar("X") - vel
					y = temblor.GetVar("Y") + vel
				elseif tipo == 3 then
					x = temblor.GetVar("X") + vel
					y = temblor.GetVar("Y") - vel
				else
					x = temblor.GetVar("X") - vel
					y = temblor.GetVar("Y") - vel
				end
				temblor.MoveToAbs(x, y)
			end
		end
	end
	for i=1,#Bubbles do
		if Bubbles[i].Comentario ~= "" then
			if ( Input.Cancel == 1 and Bubbles[i].BurbujaSkip == true ) or Bubbles[i].BurbujaSkip == "Instantaneo" then
				Bubbles[i].BurbujaSkip = "Skipeando"
				Bubbles[i].BurbujaW = 0
				while Bubbles[i].BurbujaSkip == "Skipeando" and Bubbles[i].Comentario ~= "" do
					BurbujaUpdate(i)
				end
				Bubbles[i].BurbujaW = Bubbles[i].BurbujaVelHabla
			else
				if Bubbles[i].BurbujaW <= 0 then
					BurbujaUpdate(i)
					if Bubbles[i].BurbujaWSet == false then
						Bubbles[i].BurbujaW = Bubbles[i].BurbujaVelHabla
					else
						Bubbles[i].BurbujaWSet = false
					end
				else
					Bubbles[i].BurbujaW = Bubbles[i].BurbujaW - 0.5
				end
			end
			for j=1,#Bubbles[i].Burbuja do
				if Bubbles[i].Burbuja[j].isactive then
					Bubbles[i].Burbuja[j].layer = "Top"
				end
			end
		else
			if Input.Confirm == 1 and Bubbles[i].Activo == true then
				Bubble("", "", "", "", "", "", i)
			end
		end
		for j=1,#Bubbles[i].Arcoiris do
			local epilepsia = Bubbles[i].Arcoiris[j]
			if epilepsia.GetVar("CambiarColoresArcoiris") and not ColoresArcoirisCambiados then
				ChangeColors()
			end
			if epilepsia.GetVar("PermitirArcoiris") then
				epilepsia.color = {Arcoiriscolor1/255, Arcoiriscolor2/255, Arcoiriscolor3/255}
			end
		end
		for j=1,#Bubbles[i].Shake do
			local temblor = Bubbles[i].Shake[j]
			local vel = math.random(temblor.GetVar("intensidad"),-temblor.GetVar("intensidad"))
			local tipo = math.random(4)
			if Temblortimer%2 == 0 then
				if tipo == 1 then
					x = temblor.GetVar("X") + vel
					y = temblor.GetVar("Y") + vel
				elseif tipo == 2 then
					x = temblor.GetVar("X") - vel
					y = temblor.GetVar("Y") + vel
				elseif tipo == 3 then
					x = temblor.GetVar("X") + vel
					y = temblor.GetVar("Y") - vel
				else
					x = temblor.GetVar("X") - vel
					y = temblor.GetVar("Y") - vel
				end
				temblor.MoveToAbs(x, y)
			end
		end
	end
end

function ChangeColors()
	if ArcoirisFase == "Rojo" then
		Arcoiriscolor2 = Arcoiriscolor2 + 255/45
		if Arcoiriscolor1 >= 255 and Arcoiriscolor2 >= 255 and Arcoiriscolor3 <= 0 then
			ArcoirisFase = "Amarillo"
		end
	elseif ArcoirisFase == "Amarillo" then
		Arcoiriscolor1 = Arcoiriscolor1 - 255/45
		if Arcoiriscolor1 <= 0 and Arcoiriscolor2 >= 255 and Arcoiriscolor3 <= 0 then
			ArcoirisFase = "Verde"
		end
	elseif ArcoirisFase == "Verde" then
		Arcoiriscolor3 = Arcoiriscolor3 + 255/45
		if Arcoiriscolor1 <= 0 and Arcoiriscolor2 >= 255 and Arcoiriscolor3 >= 255 then
			ArcoirisFase = "Azul Claro"
		end
	elseif ArcoirisFase == "Azul Claro" then
		Arcoiriscolor2 = Arcoiriscolor2 - 255/45
		if Arcoiriscolor1 <= 0 and Arcoiriscolor2 <= 0 and Arcoiriscolor3 >= 255 then
			ArcoirisFase = "Azul Fuerte"
		end
	elseif ArcoirisFase == "Azul Fuerte" then
		Arcoiriscolor1 = Arcoiriscolor1 + 255/45
		if Arcoiriscolor1 >= 255 and Arcoiriscolor2 <= 0 and Arcoiriscolor3 >= 255 then
			ArcoirisFase = "Morado"
		end
	elseif ArcoirisFase == "Morado" then
		Arcoiriscolor3 = Arcoiriscolor3 - 255/45
		if Arcoiriscolor1 >= 255 and Arcoiriscolor2 <= 0 and Arcoiriscolor3 <= 0 then
			ArcoirisFase = "Rojo"
		end
	end
	ColoresArcoirisCambiados = true
end